#pragma once
#include <iostream>
#include <string>
#include <cstring>
#include <cerrno>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

using namespace std;

#define Mode 0666
#define Path "testfifo"

class Fifo
{
public:
    Fifo(const string& path):_path(path)
    {
        umask(0);
        int n = mkfifo(_path.c_str(),Mode);
        if(n == 0)
        {
            cout << "mkfifo success" <<endl;
        }
        else
        {
            cout << "mkfifo failed, errno: "<< errno << " , errstring :";
            cout << strerror(errno) << endl;
        }
    }

    ~Fifo()
    {
        int n = unlink(_path.c_str());
        if(n == 0)
        {
            cout << "rmove " << _path << " success" <<endl;
        }
        else
        {
            cout << "rmove failed, errno: "<< errno << " , errstring :";
            cout << strerror(errno) << endl;
        }
    }
private:
    string _path;//文件名+文件路径
};



